# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head is None or head.next is None:
            return head
        elif head.val == head.next.val:
            head = self.getNextDifferentNode(head)
            head = self.deleteDuplicates(head)
        else:
            head.next = self.deleteDuplicates(head.next)
        return head

    def getNextDifferentNode(self, node):
        value = node.val
        while node is not None and value == node.val:
            node = node.next
        return node
